// JavaScript Document
var xmlhttp;
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
} 

/*--------------------Phat-------------------*/
//--------------list nhom ----------------//
function limitphantrang_nhom()
{
	var limit = document.getElementById("phantrang").value;
	var url ="index.php?com=nhom&fun=list&limit="+limit;
	document.location.href = url;
}
//--------------------------------------------//
function XoaThanhVienNhom(manhom, mauser)
{
	var url ="index.php?com=nhom&fun=detail&manhom="+manhom;
		url +="&mauser="+mauser;
		url +="&Type=1";
	document.location.href = url;
}
function ThemThanhVienNhom(manhom, mauser)
{
	var url ="index.php?com=nhom&fun=detail&manhom="+manhom;
		url +="&mauser="+mauser;
		url +="&Type=2";
	document.location.href = url;
}

function XoaNhom(manhom)
{
	var url ="index.php?com=nhom&fun=list&manhom="+manhom;
		url +="&Type=1";
	document.location.href = url;
}
function ThemNhom(manhom)
{
	var url ="index.php?com=nhom&fun=list&manhom="+manhom;
		url +="&Type=2";
	document.location.href = url;
}
//-----------------------them nhom-------------//
function kiemtrathemnhom()
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null )
	{
		alert ("Your browser does not support XML HTTP Request");
		return;
	}
	
	var tennhom = encodeURI(document.getElementById("addTenNhom").value);
	var mota = encodeURI(document.getElementById("addMoTa").value);
	var code = document.getElementById("security_code").value;
	var loi = document.getElementById("loithem");
	
	loi.innerHTML = "" 
	loi.style.color = "red";
	
	if ( tennhom == "" || tennhom.length < 1)
	{
		loi.innerHTML = "&nbsp;Chưa nhập tên nhóm"  ;
		return false;
	}
				
	if (mota  == "" || mota.length < 1)
	{
		loi.innerHTML = "&nbsp;Chưa nhập mô tả nhóm"  ;
		return false;
	}
	for (var i=0 ; i < tennhom.length ; i++)
	{
		if(( tennhom[i] < '0' || tennhom[i] > '9') && (tennhom[i] >'z' || tennhom[i] <'a') && (tennhom[i] >'Z' || tennhom[i] < 'A') )
		{
			loi.innerHTML = "&nbsp;Tên nhóm phải gồm kí tự a->z,0->9."  ;
			return false;
		}
	}
	
	var url ="index.php?com=nhom&fun=addnhom";
		url += "&tennhom="+tennhom ;
		url += "&mota="+mota;
		url += "&code="+code ;
		url += "&Type=1";

	document.location.href = url;
}
//--------------- them thanh vien -----------------//
function chonnhom()
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null )
	{
		alert ("Your browser does not support XML HTTP Request");
		return;
	}
	
	var manhom = document.getElementById("chonnhom").value;
	var url ="index.php?com=nhom&fun=addthanhvien";
		url += "&manhom="+manhom ;
	document.location.href = url;
}
function themthanhvien()
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null )
	{
		alert ("Your browser does not support XML HTTP Request");
		return;
	}
	var loi = document.getElementById("loithem");
	loi.innerHTML = "" 
	loi.style.color = "red";
	
	var manhom = document.getElementById("chonnhom").value;
	var mauser2 = document.getElementById("chonbanbe").value;
	if(manhom == 0)
	{
		loi.innerHTML = "&nbsp;Chưa chọn nhóm"  ;
		return false;
	}
	if(mauser2 == 0)
	{
		loi.innerHTML = "&nbsp;Chưa chọn thành viên"  ;
		return false;
	}
	var url ="index.php?com=nhom&fun=addthanhvien";
		url += "&manhom="+manhom ;
		url += "&mauser2="+mauser2 ;
		url += "&Type=1";
	document.location.href = url;
}

/*--------------------End-Phat-------------------*/

function showResult()
{
	if (xmlhttp.readyState==4 && xmlhttp.status == 200)
	{
		document.getElementById("entry").innerHTML=xmlhttp.responseText;
	}
}
